********************PSID: UNEMPLOYMENT AND LFP SWITCHING RATES********************
use "$temp/psid_employment", clear
keep if year<1998 //keep annual data only here!
merge 1:1 year uniqid using "$temp/psid_weights_2", keep(match) nogen

drop relate
sort uniqid year
ren emp empstat

//clean employment stuff
drop if empstat == 0 //na
drop if empstat == 9 //na
drop if empstat == 8 //other
drop if empstat == 7 //student

gen emp = (empstat == 1)
gen unemp = (empstat == 2 | empstat == 3)
gen nilf = (empstat>3)

gen emp_outcome = 1 if emp
replace emp_outcome = 2 if unemp
replace emp_outcome = 3 if nilf

sort uniqid year
gen emp_prev = .
replace emp_prev = emp_outcome[_n-1] if uniqid[_n] == uniqid[_n-1] & year[_n] == year[_n-1] + 1 //previous employment: last year's employment if same person and only a one-year gap

//employment persistence; 
su emp [w=weight] if emp_prev == 1 & !nilf 
local frac1 = 1 - `r(mean)'

su emp [w=weight] if emp_prev != 1 & !nilf 
local frac2 = 1 - `r(mean)'
local emp_frac = `frac1' / `frac2'

noi di "`emp_frac'"


//LFP switching rate
gen switch = 0
replace switch = 1 if ((emp_prev == 1 | emp_prev == 2) & nilf) | (emp_prev == 3 & !nilf)
replace switch = . if emp_prev == .



su switch [w=weight] if age>22 & age<=60
local switch = `r(mean)'

su switch if age>22 & age<=60 & emp_prev == 3
su switch if age>22 & age<=60 & (emp_prev == 1 | emp_prev == 2)




***************BEGIN COMPUTING MOMENTS***************
******************debt held and other moments******************
//comparative wages for hs grads and ever-enrolees age age 22-24 by ability
use "$temp/nlsy_moment_data", clear
su educ_loans_25 [fweight = weight_25] //0.15! -- 6,000 dollars.
local debt = `r(mean)'
su educ_loans_25 [fweight = weight_25] if educ_loans_25>0

local debt_n0 = `r(mean)'

gen loans_present = (educ_loans_25>0)
su loans_present [fweight = weight_25]
local debt_pres_all = `r(mean)'

su loans_present [fweight = weight_25] if parent_inc_quart == 1
local debt_pres_1 = `r(mean)'

su loans_present [fweight = weight_25] if parent_inc_quart == 2
local debt_pres_2 = `r(mean)'

su loans_present [fweight = weight_25] if parent_inc_quart == 3
local debt_pres_3 = `r(mean)'

su loans_present [fweight = weight_25] if parent_inc_quart == 4
local debt_pres_4 = `r(mean)'

*********************ASSEMBLY*********************
clear
set obs 12
gen moment = .
//replace moment = `debt' in 1
replace moment = `switch' in 1
replace moment =  `emp_frac' in 2 //swapped around so that it gets comparable weight
replace moment = 0.71 in 3 //lovenheim: extra 10k in house value increases college attendance by 0.7 percetn
replace moment = 5.67 in 4 //lovenheim: extra 10k increases college attendanc by 5.7 percent if income<70k
replace moment = 0.43 in 5 //hilger: decrease in 8200 in income drops college attendance by 0.43 pp
replace moment = `debt' in 6
replace moment = `debt_n0' in 7
replace moment = `debt_pres_all' in 8
replace moment = `debt_pres_1' in 9
replace moment = `debt_pres_2' in 10
replace moment = `debt_pres_3' in 11
replace moment = `debt_pres_4' in 12



export delimited "$model/moments/additional_moments.csv", novarn replace



//end of dofile
